package com.longjiyi.test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class 移动零快慢指针做法 {
    public static void main(String[] args) {
        int[] ints = new int[5];
        ints[0] = 0;
        ints[1] = 1;
        ints[2] = 0;
        ints[3] = 3;
        ints[4] = 12;
        moveZeroes(ints);
    }

    public static void moveZeroes(int[] nums) {
        int slow = 0, fast = 0;
        while (fast < nums.length) {
            if (nums[fast] == 0) {
                fast++;
            } else {
                nums[slow] = nums[fast];
                fast++;
                slow++;
            }
        }
        for (int i = slow; i < nums.length; i++) {
            nums[i] = 0;
        }

        System.out.println(Arrays.toString(nums));
    }
}
